//
//  SYStatusForwardCell.swift
//  SingWeibo
//
//  Created by shiying on 15/12/21.
//  Copyright © 2015年 shiying. All rights reserved.
//

import UIKit

class SYStatusForwardCell: SYStatusCell {

    /// 重写父类方法，必须前面加上 override
    override var status: SYStatus? { //转发内容
        didSet {
               if let forwardStatus = status?.retweeted_status {
                //名称
                let name = forwardStatus.user!.screen_name!
                let attrText = forwardStatus.attrText
         
                let attrM = NSMutableAttributedString(string: name)
                attrM.appendAttributedString(attrText!)
                forwardLabel.attributedText = attrM
            }
        }
    }
    override func prepareUI() {
        
        super.prepareUI()
        // 添加
        contentView.addSubview(backGroundButton)
        contentView.addSubview(forwardLabel)
        // 将他带到最后面
        contentView.sendSubviewToBack(backGroundButton)
        
        backGroundButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
        backGroundButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backGroundButton, size: nil, offset: CGPoint(x: 8, y: 8))
        
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * SYStatusCellMargin))
        
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: 8))
        
        pictureViewWidthCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)

        
    }

    
    //MARK: - 懒加载
    lazy var backGroundButton: UIButton = {
        let button = UIButton()
        
        button.backgroundColor = UIColor(white: 0.8, alpha: 1)
        button.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
    lazy var forwardLabel: UILabel = {
        let label = UILabel(fontSize: 14, color: UIColor.darkGrayColor())
        label.numberOfLines = 0
        
        return label
    }()
    
    func buttonClick() {
        let status = self.status!.retweeted_status!
        delegate?.forwradOnTheClick(status)
        
    }
    
    
}
